// pages/cf-list/cf-list.js
var app = getApp()
var modal = require('../../utils/modal');
var request = require('../../utils/request');
var utils = require('../../utils/utils');
var comment = require('../widget/comment/comment');
var goTop = require('../widget/goTop/goTop');

var pageSetting = {
  data: {
    size: 10,
    offset: 0,
    has_more: 1,
    total: 0,
    listData: [],
    shareShow:0
  },
  onLoad: function () {
    this.loadList();
  },
  onShareAppMessage: function (res) {
    return {
      title: '企鹅优品的这些众筹项目都不错哦，来看看吧',
      path: '/pages/zc-list/zc-list',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  onReachBottom: function () {
    this.loadList();
  },  
  loadList: function () {
    var that = this;
    if (that.data.has_more) {
      var data = {
        "zp:zc_api:act:index":
        {
          "offset": that.data.offset,
          "size": that.data.size
        }
      };
      modal.loading();
      request.post({
        path: '/wxapp_api/api'
      }, data).then(function (res) {
        modal.hide();       
        if (res['zp:zc_api:act:index'].ret== 0) {          
          that.data.offset = res['zp:zc_api:act:index'].data.offset;
          that.data.has_more = res['zp:zc_api:act:index'].data.has_more;
          that.data.total += res['zp:zc_api:act:index'].data.total;
          for (var i = 0; i < res['zp:zc_api:act:index'].data.list.length; i++) {         
            that.data.listData.push(res['zp:zc_api:act:index'].data.list[i]);
          }
          that.setData({
            offset: that.data.offset,
            has_more: that.data.has_more,
            total: that.data.total,
            listData: that.data.listData
          });          
        }else{
          modal.toast(res['zp:zc_api:act:index']['msg']);
        }
      });
    }
  },
  showShareModal: function () {
    this.data.shareShow = 1;
    this.setData({
      shareShow: this.data.shareShow
    });
  },
  hideShareModal:function(){
    this.data.shareShow=0;
    this.setData({
      shareShow: this.data.shareShow
    });
  }
};
Page(pageSetting)